package hibernateDAOS;

import hibernate.HibernateUtil;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;


import beans.Comision;

public class ComisionDAO {
	
	private static ComisionDAO instancia = null;
	private static SessionFactory sf = null;

	public static ComisionDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new ComisionDAO();
		} 
		return instancia;
	}
	
	public void guardarComision(Comision c){
		Session session = sf.openSession();
		session.beginTransaction();
		session.save(c);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public void eliminarComision(Comision c){
		Session session = sf.openSession();
		session.beginTransaction();
		session.delete(c);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public void modificarComision(Comision m){
		Session session = sf.openSession();
		session.beginTransaction();
		session.saveOrUpdate(m);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	@SuppressWarnings("unchecked")
	public List<Comision> obtenerComisions(){
		Session session = sf.openSession();
		Query q = session.createQuery("from Comisiones");
		List<Comision> comisiones = q.list();
		session.close();
		return comisiones;
	}
}



